package com.ihr360.payroll.model.dto.staff;

import com.ihr360.commons.model.type.TaxRole;
import com.ihr360.commons.model.type.WorkHourType;
import com.ihr360.payroll.model.dto.salary.basecode.TaxDivision;
import com.ihr360.payroll.model.dto.staff.embeddable.StaffBankCard;
import com.ihr360.shared.basicstaffinfo.dto.SyncedBasicStaffInfo;
import com.ihr360.shared.entitywithlistener.NumberIdWithTimeAndCompanyId;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Date;

/**
 * 员工工资相关的信息子集
 */
@Entity
@Table(indexes = {
        @Index(name = "company_staff_idx", columnList = "companyId,staffId", unique = true)})
@TypeDefs({
        @TypeDef(name = "json", typeClass = JsonStringType.class),
        @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class StaffPayrollInfo extends NumberIdWithTimeAndCompanyId<Long> {

    public static final class Field {
        public static final String STAFF_ID = "staff.id";
    }

    /**
     * 员工信息
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "staffId", nullable = false)
    private SyncedBasicStaffInfo staff;

    /**
     * 员工的工时类型
     */
    @Enumerated(value = EnumType.STRING)
    private WorkHourType workHourType;

    @ManyToOne
    @JoinColumn(name = "taxDivisionId")
    private TaxDivision taxDivision;

    /**
     * 薪资最后发放月
     */
    @Column(columnDefinition = "DATE")
    private Date payEndOn;

    /**
     * 纳税身份
     */
    @Enumerated(EnumType.STRING)
    private TaxRole taxRole = TaxRole.NATIVE;

    /**
     * 银行卡信息
     * */
    @Embedded
    private StaffBankCard staffBankCard;

    /**
     * 本年度累计免税额（残疾人）
     *
     */
    private Double taxExemption;

    public Double getTaxExemption() {
        return taxExemption;
    }

    public void setTaxExemption(Double taxExemption) {
        this.taxExemption = taxExemption;
    }

    public StaffBankCard getStaffBankCard() {
        return staffBankCard;
    }

    public void setStaffBankCard(StaffBankCard staffBankCard) {
        this.staffBankCard = staffBankCard;
    }

    public SyncedBasicStaffInfo getStaff() {
        return staff;
    }

    public void setStaff(SyncedBasicStaffInfo staff) {
        this.staff = staff;
    }

    public WorkHourType getWorkHourType() {
        return workHourType;
    }

    public void setWorkHourType(WorkHourType workHourType) {
        this.workHourType = workHourType;
    }

    public TaxDivision getTaxDivision() {
        return taxDivision;
    }

    public void setTaxDivision(TaxDivision taxDivision) {
        this.taxDivision = taxDivision;
    }

    public TaxRole getTaxRole() {
        return taxRole;
    }

    public void setTaxRole(TaxRole taxRole) {
        this.taxRole = taxRole;
    }

    public Date getPayEndOn() {
        return payEndOn;
    }

    public void setPayEndOn(Date payEndOn) {
        this.payEndOn = payEndOn;
    }
}
